<?php

class Pager extends AbstractPager {

    public function display() {
        $start_page = $this->getStartPage();
        $end_page = $this->getEndPage();
        $next_page = $this->getNextPage();
        $back_page = $this->getBackPage();
        $attrs = $this->getAttributePage();
        $query_string = $this->getQueryString();
        $link = $this->link . "?" . $query_string;
        $page_name = $this->pattern["page_query_string"];

        if ($back_page < $this->page) {
            echo "<a class='" . $this->pattern['page_class_css'] . "' href='" . $link . "&$page_name=" . $back_page . "'>" . $this->pattern["back_page"] . "</a>" . $this->pattern["seperate"];
        }

        if (!in_array($start_page, $attrs)) {
            echo "<a class='" . $this->pattern['page_class_css'] . "' href='" . $link . "&$page_name=" . $start_page . "'>" . ($this->pattern["first_page"] != "" ? $this->pattern["first_page"] : $this->getStartPage()) . "</a>" . $this->pattern["seperate"];
        }
        
        $sizeAttrs = count($attrs);
        if($sizeAttrs > 1){
            for ($i = 0; $i < $sizeAttrs; $i++) {
                if ($i > 0) {
                    echo $this->pattern["seperate"];
                }
                if ($attrs[$i] == $this->page) {
                    echo "<a class='" . $this->pattern['current_page_class_css'] . "' href='" . $link . "&$page_name=" . $attrs[$i] . "'>" . $attrs[$i] . "</a>";
                } else {
                    echo "<a class='" . $this->pattern['page_class_css'] . "' href='" . $link . "&$page_name=" . $attrs[$i] . "'>" . $attrs[$i] . "</a>";
                }
            }
        }
        if (!in_array($end_page, $attrs)) {
            echo $this->pattern["seperate"] . "<a class='" . $this->pattern['page_class_css'] . "' href='" . $link . "&$page_name=" . $end_page . "'>" . ($this->pattern["last_page"] != "" ? $this->pattern["last_page"] : $this->getEndPage()) . "</a>";
        }

        if ($next_page > $this->page) {
            echo $this->pattern["seperate"] . "<a class='" . $this->pattern['page_class_css'] . "' href='" . $link . "&$page_name=" . $next_page . "'>" . $this->pattern["next_page"] . "</a>";
        }
    }

}
